﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;


namespace QuanLyTruongMamNon
{
    class Thu_Vien
    {
        //    public static SqlConnection Taoketnoi()
        //    {
        //        return new SqlConnection("Provider=SQLOLEDB;Data Source=(local);Initial Catalog=QLTMN;Persist Security Info=True;User ID=sa;Password=***********");
        //    }

        //    public static DataTable Taobang(string Sql)
        //    {

        //        SqlConnection conn = Taoketnoi();
        //        SqlDataAdapter ad = new SqlDataAdapter(Sql, conn);
        //        DataTable dt = new DataTable();
        //        ad.Fill(dt);
        //        return dt;
        //    }

        //    public void ExcuteNonQuery(string sql)
        //    {
        //        SqlConnection Con = Taoketnoi();
        //        SqlCommand cmd = new SqlCommand(sql, Con);
        //        Con.Open();
        //        cmd.ExecuteNonQuery();
        //        Con.Close();
        //        cmd.Dispose();
        //    }
        //}

        public static String _connectionString = "Provider=SQLOLEDB;server=(local);database=QLTMN;uid=sa;pwd=sa";
       // protected static String _connectionString = "Provider=SQLOLEDB;Data Source=user-pc;Initial Catalog=QLTMN;Integrated Security=SSPI;";
        public static OleDbConnection connection;

        public static void OpenConnection()
        {
            try
            {
             
                  connection = new OleDbConnection();
                  connection.ConnectionString = _connectionString;
                  connection.Open();
       
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void CloseConnection()
        {
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
        //TAO BANG DU LIEU
        public static DataTable ExecuteQuery(string sql)
        {
            OpenConnection();
            DataTable dt = new DataTable();
            OleDbCommand command = connection.CreateCommand();
            command.CommandText = sql;
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = command;
            adapter.Fill(dt);
            CloseConnection();
            return dt;
        }
        //CAP NHAT BANG
        public static void ExecuteNonQuery(string sql)
        {
            OpenConnection();
            OleDbCommand command = connection.CreateCommand();
            command.CommandText = sql;
            command.ExecuteNonQuery();
        }
        public static void DocBangTheo_DK(string sql, string dk)
        {

        }
    }
};

 

